import axios from 'axios';

let base = -1 === window
    .location
    .href
    .indexOf("http://localhost")
    ? "https://wx.hulupi.com/cityfood/manage"
    : "";

export const requestLogin = params => {
    return axios
        .post(`${base}/adminUser/login`, params)
        .then(res => res.data);
};

export const getUserList = params => {
    return axios.get(`${base}/user/list`, {params: params});
};

export const getUserListPage = params => {
    return axios.get(`${base}/userLikePhone`, {params: params});
};

export const removeUser = params => {
    return axios.get(`${base}/user/remove`, {params: params});
};

export const batchRemoveUser = params => {
    return axios.get(`${base}/user/batchremove`, {params: params});
};

export const editUser = params => {
    return axios.get(`${base}/user/edit`, {params: params});
};

export const addUser = params => {
    return axios.get(`${base}/user/add`, {params: params});
};

export const getCityListPage = params => {
    return axios.get(`${base}/citys`, params);
};

export const getAllCitys = params => {
    return axios.get(`${base}/allCitys`,params);
};

export const addCity = params => {
    return axios
        .post(`${base}/citys`, params)
        .then(res => res.data);
};

export const editCity = params => {
    return axios
        .put(`${base}/citys`, params)
        .then(res => res.data);
};

export const removeCity = params => {
    return axios.delete(`${base}/citys/remove`, {params: params});
};

export const batchRemoveCity = params => {
    return axios.delete(`${base}/citys/batchremove`, {params: params});
};

export const adminLogin = params => {
    return axios
        .post(`${base}/adminUser/login`, params)
        .then(res => res.data);
};

//系统管理
export const fetchSysUsers = params => {
    console.log("fetchSysUsers");
    console.log(params);
    return axios
        .get(`${base}/adminUser`, params)
        .then(res => res.data);
};

//添加
export const addSysUser = params => {
    console.log("addSysUser");
    console.log(params);
    return axios
        .post(`${base}/adminUser`, params)
        .then(res => res.data);
};

//编辑
export const editSysUser = params => {
    console.log("editSysUser");
    console.log(params);
    return axios
        .put(`${base}/adminUser`, params)
        .then(res => res.data);
};

//删除
export const removeSysUser = params => {
    console.log("removeSysUser");
    console.log(params);
    return axios
        .delete(`${base}/adminUser/` + params, undefined)
        .then(res => res.data);
};

//查询详情
export const fetchSysUserDetail = params => {
    console.log("fetchSysUserDetail");
    console.log(params);
    return axios
        .get(`${base}/adminUser/` + params, undefined)
        .then(res => res.data);
};

//商品管理
export const fetchProducts = params => {
    console.log("fetchProducts");
    console.log(params);
    return axios
        .get(`${base}/product`, {params: params})
        .then(res => res.data);
};

//addProduct
export const addProduct = params => {
    console.log("addProduct");
    params.attributeList = JSON.stringify(params.productAttrs);
    console.log(params);
    return axios
        .post(`${base}/product`, params)
        .then(res => res.data);
};
export const editProduct = params => {
    console.log("editProduct");
    params.attributeList = JSON.stringify(params.productAttrs);
    console.log(params);
    return axios
        .put(`${base}/product`, params)
        .then(res => res.data);
};

export const removeProduct = params => {
    console.log("removeProduct");
    console.log(params);
    return axios
        .delete(`${base}/product/remove`, params)
        .then(res => res.data);
};

export const batchRemoveProduct = params => {
    console.log("batchRemoveProduct");
    console.log(params);
    return axios
        .delete(`${base}/product/batchremove`, params)
        .then(res => res.data);
};

//评价管理
export const fetchComments = params => {
    console.log("fetchComments");
    console.log(params);
    return axios
        .get(`${base}/comment`, params)
        .then(res => res.data);
};

export const removeComment = params => {
    console.log("removeComment");
    console.log(params);
    return axios
        .delete(`${base}/comment/remove`, params)
        .then(res => res.data);
};

export const batchRemoveComments = params => {
    console.log("batchRemoveComments");
    console.log(params);
    return axios
        .delete(`${base}/comment/batchremove`, params)
        .then(res => res.data);
};

//商品规格管理
export const fetchSpecs = params => {
    console.log("fetchSpecs");
    console.log(params);
    return axios
        .get(`${base}/specs`, params)
        .then(res => res.data);
};

export const removeSpec = params => {
    console.log("removeSpec");
    console.log(params);
    return axios
        .delete(`${base}/specs/remove`, params)
        .then(res => res.data);
};

export const batchRemoveSpecs = params => {
    console.log("batchRemoveSpecs");
    console.log(params);
    return axios
        .delete(`${base}/specs/batchremove`, params)
        .then(res => res.data);
};

//订单管理

export const fetchOrders = params => {
    console.log("orders");
    console.log(params);
    return axios
        .get(`${base}/orders`, {params: params})
        .then(res => res.data);
};


//分类管理
export const fetchAllCategorys = params => {
    console.log("fetchAllCategorys");
    console.log(params);
    return axios
        .get(`${base}/allCategorys`, {params: params})
        .then(res => res.data);
};

//系统管理
export const fetchCategorys = params => {
    console.log("fetchCategorys");
    console.log(params);
    return axios
        .get(`${base}/categorys`, params)
        .then(res => res.data);
};

//添加
export const addCategory = params => {
    console.log("addCategory");
    console.log(params);
    return axios
        .post(`${base}/categorys`, params)
        .then(res => res.data);
};

//编辑
export const editCategory = params => {
    console.log("editCategory");
    console.log(params);
    return axios
        .put(`${base}/categorys`, params)
        .then(res => res.data);
};

//删除
export const removeCategory = params => {
    console.log("removeCategory");
    console.log(params);
    return axios
        .delete(`${base}/categorys/remove`, params)
        .then(res => res.data);
};



//高铁战管理

export const fetchStations = params => {
    console.log("fetchStations");
    console.log(params);
    return axios
        .get(`${base}/station`, params)
        .then(res => res.data);
};

//添加
export const addStation = params => {
    console.log("addStation");
    console.log(params);
    return axios
        .post(`${base}/station`, params)
        .then(res => res.data);
};

//编辑
export const editStation = params => {
    console.log("editStation");
    console.log(params);
    return axios
        .put(`${base}/station`, params)
        .then(res => res.data);
};

//删除
export const removeStation = params => {
    console.log("removeStation");
    console.log(params);
    return axios
        .delete(`${base}/station/remove`, params)
        .then(res => res.data);
};

export const batchremoveStation = params => {
    console.log("batchremoveStation");
    console.log(params);
    return axios
        .delete(`${base}/station/batchremove`, params)
        .then(res => res.data);
};